package com.wzl.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzl.constant.CommonConstant;
import com.wzl.entity.dto.ContactsInfoDTO;
import com.wzl.service.ContactsInfoService;
import com.wzl.util.Res;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("contactsInfo")
@AllArgsConstructor
public class ContactsInfoController {
    @Autowired
    private ContactsInfoService contactsInfoService;

    /**
     * 查询密切接触者信息
     *
     * @param contactsInfoDTO
     * @return Res
     */
    @PreAuthorize("@pm.hasPermission('sys:contacts:view')")
    @GetMapping("list")
    public Res list(Page<ContactsInfoDTO> page, ContactsInfoDTO contactsInfoDTO) {
        return Res.success(contactsInfoService.getPage(page, contactsInfoDTO));
    }


    /**
     * 新增密切接触者信息
     *
     * @param contactsInfo
     * @return com.longyi.util.Res
     */
    @PreAuthorize("@pm.hasPermission('sys:contacts:add')")
    @PostMapping("addContactsInfo")
    public Res create(@RequestBody ContactsInfoDTO contactsInfo) {
        boolean b = this.contactsInfoService.saveContactsInfo(contactsInfo);
        return b ? Res.success(b) : Res.fail(CommonConstant.DICT_FAILED);
    }

    /**
     * 查询密切接触者详情
     *
     * @param id
     * @return Res
     */
    @PreAuthorize("@pm.hasPermission('sys:contacts:detail')")
    @GetMapping("detail/{id}")
    public Res contactDetail(@PathVariable("id")String id) {
        return Res.success(contactsInfoService.contactDetail(id));
    }

    /**
     * 删除密切接触者信息
     *
     * @param id
     * @return Res
     */
    @PreAuthorize("@pm.hasPermission('sys:contacts:delete')")
    @GetMapping("delete/{id}")
    public Res deleteContact(@PathVariable("id")String id) {
        return Res.success(contactsInfoService.deleteContact(id));
    }

    /**
     * 修改密切接触者信息
     *
     * @param contactsInfo
     * @return Res
     */
    @PreAuthorize("@pm.hasPermission('sys:contacts:update')")
    @PostMapping("update")
    public Res updateContact(@RequestBody ContactsInfoDTO contactsInfo) {
        return Res.success(contactsInfoService.updateContact(contactsInfo));
    }


}
